package com.hy.day;

import java.util.Arrays;
import java.util.Comparator;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * <p>
 * User:Mr.Du
 * Date:2024/7/31
 * Time:9:00
 */
public class MinRectanglesToCoverPoints {

    public static void main(String[] args) {
        int[][] points = {
                {0, 1000000000}, {0, 999999999}, {0, 999999998}, {0, 999999997},
                {0, 999999996}, {0, 999999995}, {0, 999999994}, {0, 999999993},
                {0, 999999992}, {0, 999999991}, {0, 999999990}, {0, 999999989},
                {0, 999999988}, {0, 999999987}, {0, 999999986}, {0, 999999985},
                {0, 999999984}, {0, 999999983}, {0, 999999982}, {0, 999999981},
                {0, 999999980}, {0, 999999979}, {0, 999999978}, {0, 999999977},
                {0, 999999976}, {0, 999999975}, {0, 999999974}, {0, 999999973},
                {0, 999999972}, {0, 999999971}, {0, 999999970}, {0, 999999969},
                {0, 999999968}, {0, 999999967}, {0, 999999966}, {0, 999999965},
                {0, 999999964}, {0, 999999963}, {0, 999999962}, {0, 999999961},
                {0, 999999960}, {0, 999999959}, {0, 999999958}, {0, 999999957},
                {0, 999999956}, {0, 999999955}, {0, 999999954}, {0, 999999953},
                {0, 999999952}, {0, 999999951}, {0, 999999950}, {0, 999999949},
                {0, 999999948}, {0, 999999947}, {0, 999999946}, {0, 999999945},
                {0, 999999944}, {0, 999999943}, {0, 999999942}, {0, 999999941},
                {0, 999999940}, {0, 999999939}, {0, 999999938}, {0, 999999937},
                {0, 999999936}, {0, 999999935}, {0, 999999934}, {0, 999999933},
                {0, 999999932}, {0, 999999931}, {0, 999999930}
        };
        System.out.println(minAreaRect(points, 1));
    }

    public static int minAreaRect(int[][] points, int w) {
        int n = points.length, res = 1;
        Arrays.sort(points, Comparator.comparingInt(a -> a[0]));
        int f = points[0][0];
        for (int i = 1; i < n; i++) {
            if (f == points[i][0]) continue;
            if (points[i][0] - f > w) {
                res++;
                f = points[i][0];
            }
        }
        return res;
    }

}
